﻿<!DOCTYPE html>
<html class="x-admin-sm">

<head>
    <meta charset="UTF-8">

    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
        content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />



    <link rel="stylesheet" href="../content/css/font.css">
    <link rel="stylesheet" href="../content/css/xadmin.css">
    <link rel="stylesheet" href="../content/plugin/bootstrap/css/bootstrap.min.css">
    <link rel='stylesheet' href='../content/plugin/bootstrap/css/style.css' />

    <script src="../content/js/jquery-1.10.2.min.js"></script>

    <script type="text/javascript" src="../content/js/xadmin.js"></script>
    <script type="text/javascript" src="../content/js/md5.min.js"></script>
    <script type="text/javascript" src="../content/js/cookie.js"></script>
    <script src="../content/lib/layui/layui.js" charset="utf-8"></script>
    <link rel="stylesheet" href="../content/plugin/FileUpload/css/jquery.fileupload.css" />




</head>

<body>
    <div id="app">
        <div class="x-nav">

            <span class="nav-header">
                <a href="">库存管理</a>

            </span>

        </div>
        <div class="x-body">
            <div class="layui-row">
                商品名称:
                <input type="text" name="username" placeholder="" v-model="search.goods_name" autocomplete="off"
                    style="height:30px;width: 100px;">
                编码:
                <input type="text" placeholder="" v-model="search.code" autocomplete="off"
                    style="height:30px;width: 100px;">


                <button class="layui-btn" v-on:click="getdata"><i class="layui-icon">&#xe615;</i></button>


            </div>
            <hr />



            <div class="table-responsive">
                <table class="table table-bordered table-hover">
                    <thead>
                        <tr>
                            <th>
                                序号</th>
                            <th>
                                商品ID</th>
                            <th> 商品图片</th>
                            <th>商品名称</th>
                            <th>编码</th>
                            <th> 商品分类</th>
                            <th> 当前库存</th>



                        </tr>
                    </thead>
                    <tbody>
                        <tr v-for="(uitem,i) in arrayData">


                            </td>
                            <td>{{i+1}}</td>
                            <td>{{uitem.id}}</td>
                            <td>
                                <img :src="uitem.imgurl" style="width: 50px;height: 50px; object-fit: cover;
                                " />
                            </td>
                            <td>{{uitem.goods_name}}</td>
                            <td>{{uitem.goods_no}}</td>
                            <td>{{uitem.typename}}</td>



                            <td>{{uitem.num}}</td>


                        </tr>
                    </tbody>
                </table>
            </div>


        </div>

        <!--添加-->
        <div class="modal fade" id="addbox" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
            <div class="modal-dialog">
                <div class="modal-content" id="myModal">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                            <span aria-hidden="true">&times;</span>
                        </button>
                        <h4 class="modal-title" id="myModalLabel">库存</h4>
                    </div>
                    <div class="modal-body">
                        <fieldset>
                            <div class="control-group">
                                <label for="input01" class="control-label">商品名称</label>
                                <div class="controls">
                                    {{addobj.name}}
                                </div>
                            </div>
                            <div class="control-group">
                                <label for="input01" class="control-label">商品规格</label>
                                <div class="controls">
                                    {{addobj.format}}
                                </div>
                            </div>
                            <div class="control-group">
                                <label for="input01" class="control-label">现库存</label>
                                <div class="controls">
                                    {{addobj.num}}
                                </div>
                            </div>

                            <div class="control-group">
                                <label for="input01" class="control-label">补货数量</label>
                                <div class="controls">
                                    <input placeholder="" type="text" class="form-control" v-model="addobj.stock_num">
                                </div>
                            </div>





                        </fieldset>
                        <div class="modal-footer">
                            <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                            <button type="button" class="btn btn-primary" v-on:click="insert()">确认</button>
                        </div>
                    </div>
                </div>
            </div>
        </div>



    </div>
    <link href="../content/plugin/sweetalert/sweetalert.css" rel="stylesheet">
    <script src="../content/plugin/sweetalert/sweetalert.min.js"></script>
    <script src="../content/plugin/bootstrap/js/bootstrap.min.js"></script>
    <script src="../content/js/vue2.js"></script>
    <script src="../content/js/vue-nav.js"></script>
    <script src="../content/js/config.js"></script>

    <script>


        Array.prototype.remove = function (val) {
            var index = this.indexOf(val);
            if (index > -1) {
                this.splice(index, 1);
            }
        };
        var vm = new Vue({
            el: "#app",
            data: {
                all: 0,
                search: {
                    page: 1,
                    rows: 10,
                    mid: localStorage.getItem("mid")

                },
                arrayData: [],
                allcount: 0,
                menulist: [],
                addobj: {
                    stock_num: 0
                },
                ids: [],
                editobj: {},
                datalist: [],
                statelist: [{ "id": "1", "name": "是" }, { "id": "0", "name": "否" }],
                statelist1: [{ "id": "1", "name": "上架" }, { "id": "0", "name": "下架" }],
                chooseall: false,
                bili: 0,
                goodid: 0,
            },
            components: {
                'vue-nav': Vnav
            },
            methods: {
                check() {
                    if (localStorage.getItem("mid") == "0") {
                        return true;
                    } else {
                        return false;
                    }
                },
                searchdata: function () {
                    this.search.page = 1;
                    this.getdata();
                },

                addhang: function () {

                    if (this.datalist == null) {
                        this.datalist = [];
                    }
                    console.log("addhang", this.datalist);
                    var datalist = this.datalist;
                    datalist.push({});
                    this.datalist = datalist;
                },

                delcode: function (uitem) {
                    var datalist = this.datalist;
                    datalist.remove(uitem);
                    this.datalist = datalist;
                },
                getdata: function (_keycontent) {  //查询数据

                    var self = this;
                    $.post(apiurl + "/admin/goods/kucun", this.search, function (_result) {
                        console.log(_result);
                        self.arrayData = _result.data;

                    });

                },

                view: function (uitem) {

                    if (uitem.goods_no == null || uitem.goods_no == "") {
                        layer.msg("编码为空不能补货");
                        return;
                    }
                    var that = this;

                    $.post(apiurl + "/admin/jxc/productdata/info", { code: uitem.goods_no }, function (_result) {

                        console.log("_result", _result);
                        if (_result.status == 200) {

                            that.addobj = _result.data;
                            $("#addbox").modal('show');
                        } else {
                            layer.msg("没有库存");
                            return;
                        }


                    });

                },
                insert: function () {
                    var self = this;


                    if (this.addobj.stock_num > this.addobj.num) {
                        layer.msg("补货数量不能大于库存数量");
                        return;
                    }
                    console.log("ss", this.addobj);
                    this.addobj.productid = this.addobj.id;

                    $.post(apiurl + "/admin/goods/buhuo", this.addobj, function (_result) {
                        if (_result.status == "200") {
                            swal("success", _result.message, "success");
                            $("#addbox").modal('hide');
                            self.getdata();
                        } else {

                            swal("error", _result.message, "error");
                        }

                    });


                },
                vdel: function (uitem) {
                    var self = this;
                    swal({
                        title: "确定要删除吗?",
                        text: "",
                        type: "warning",
                        showCancelButton: true,
                        confirmButtonColor: "#DD6B55",
                        confirmButtonText: "是",
                        cancelButtonText: '否',
                        closeOnConfirm: false
                    }, function () {

                        $.ajax({
                            url: apiurl + '/admin/dian/applygoods/del',
                            type: 'DELETE',
                            data: { "goodid": uitem.id, mid: localStorage.getItem("mid") },
                            success: function (result) {
                                if (result.status == 200) {
                                    swal("系统提示", "已删除", "success");
                                    self.getdata("");
                                } else {
                                    swal("系统提示", "系统异常", "success");
                                }
                            }
                        });

                    });
                },


            },
            created: function () {  //初始化事件里边去调用查询方法


                var page = GetRequest("page");



                if (page != undefined && page != null) {
                    this.search.page = parseInt(page);
                }


                this.getdata();


            }
        });


    </script>
</body>

</html>